import {
  createStore
} from 'vuex'

export default createStore({
  //定义所需要的状态
  state: {
    name: 'state里的name',
    list: [{
        title: '吃饭饭',
        complete: false
      },
      {
        title: '睡觉觉',
        complete: false
      },
      {
        title: '打豆豆',
        complete: true
      },
      {
        title: '6666',
        complete: true
      }

    ]
  },
  //同步修改state 都是方法
  mutations: {
    setName(state, payload) {
      state.name = payload
    },
    addTodo(state, payload) {
      state.list.push(payload)
    },
    delTOdo(state, payload) {
      state.list.splice(payload, 1)
    },
    clear(state,payload){
      state.list=payload
    }

  },
  //异步提交 mutations
  //第一个参数
  actions: {
    asyncSetName() {
      setTimeout((store, params) => {
        //commit 用来提交mutations
        store.commit('setName', params)
      }, 2000)
    }
  },
  modules: {}
})